package cn.wolfcode.rbac.query;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;
@Setter
@Getter
public class PageResult {
    private int currentPage;
    private int pageSize;
    private int rows;
    private List<?> list;
    private int prevPage;
    private int nextPage;
    private int endPage;

    public PageResult(int currentPage, int pageSize, int rows, List<?> list) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.rows = rows;
        this.list = list;
        if (rows <= pageSize) {
            prevPage = 1;
            nextPage = 1;
            endPage = 1;
            return;
        }
        endPage = rows % pageSize == 0 ? rows / pageSize : rows / pageSize + 1;
        prevPage = currentPage >= 2 ? currentPage - 1 : 1;
        nextPage = currentPage < endPage ? currentPage + 1 : endPage;
    }

    public PageResult(int pageSize) {
        this(1, pageSize, 0, Collections.EMPTY_LIST);
    }

}
